
//
//  CinemaViewController.m
//  DSYDouban
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "CinemaViewController.h"
#import "CinemaCell.h"
#import "CinemaModel.h"

@interface CinemaViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

@property (nonatomic, retain) NSMutableArray *cinemaArr;

@end

@implementation CinemaViewController

- (void)dealloc
{
    [_tableView release];
    [_cinemaArr release];
    
    
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"影院";
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
    [_tableView release];
    
    // 数据加载
    [self dataHandle];
    
    [_tableView registerClass:[CinemaCell class] forCellReuseIdentifier:@"cinemaCell"];
}

// 数据加载
- (void)dataHandle {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cinema" ofType:@"plist"];
    
    NSArray *tempArr = [NSArray arrayWithContentsOfFile:path];
    
    self.cinemaArr = [NSMutableArray array];
    
    for (NSDictionary *dic in tempArr) {
        
        CinemaModel *model = [CinemaModel cinemaModel];
        [model setValuesForKeysWithDictionary:dic];
        
        [_cinemaArr addObject:model];
    }
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CinemaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cinemaCell" forIndexPath:indexPath];
    
    
    CinemaModel *model = _cinemaArr[indexPath.row];
    
    cell.cinemaNameLabel.text = model.cityName;
    cell.addressLabel.text = model.address;
    cell.telephoneLabel.text = model.telephone;
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 180;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _cinemaArr.count;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
